/**
 * *印厂对账：选择单据按钮事件
 */
function chooseYCDZ() {
    // 获取付款对象
    var MAN_ID = $('#ycdz_addWinForm').find('input[qucln=MAN_ID]').val();
    if (MAN_ID == '') {
        $.messager.alert('提示', '请选择付款对象！');
        return;
    }
    _data_qw('yct', 'ds_yc_jslist_item2', 'ycdz_sure1', '44', 'yctQuery', '');
}

//选择单据弹出窗口的回调函数
function yctQuery() {
    $('#yct_dataQuery').attr('onclick', 'ycdzQuery(this)');
}

//印厂对账的选择单据的查询按钮
function ycdzQuery(obj) {
    var prefix = $(obj).attr('pre');
    var dsId = $(obj).attr('dsid');
    var resultDG = 'DATA_DATALIST';
    var comUseConf = 'commUseD';
    var otherConfig = "";
    //获取印刷复印单的主键列
    var peId = $('#ycdz_addWinTable input[qucln=MAN_ID]').val();
    if (peId == '' || peId == null) {
        peId = 'null';
    }
    otherConfig = "1-MAN_ID-" + peId + "-inc|+";
    var comUse = parseConfig(prefix + "_" + comUseConf);
    var useConf = otherConfig + comUse;
    $('#' + prefix + "_" + resultDG).datagrid({
        url: _m_url + 'framework/loadDataQ',
        queryParams: {'dsId': dsId, 'config': useConf},
        onLoadSuccess: function () {

        }
    });
}

/**
 * 弹窗的确定按钮
 *
 * @return
 */
function ycdz_sure1() {
    // 关闭弹窗
    $('#yct_DATA_PARENT_PANEL').window('close');
    // 原有明细数据
    var oldRows = $('#ycdz_addItemDatagrid').datagrid('getRows');
    // 获取选择的数据
    var selRows = $('#yct_DATA_DATALIST').datagrid('getSelections');

    // 关闭弹出窗口的editor
    for (var i = 0; i < selRows.length; i++) {
        var index = $('#yct_DATA_DATALIST').datagrid("getRowIndex", selRows[i]);
        $('#yct_DATA_DATALIST').datagrid('endEdit', index);
    }

    for (var j = 0; j < selRows.length; j++) {
        var b = false;
        for (var i = 0; i < oldRows.length; i++) {
            if (oldRows[i].DJ_CODE == selRows[j].DJ_CODE && oldRows[i].H_ID == selRows[j].H_ID ) {
                //$.messager.alert('提示', '该'+(oldRows.length+j)+'行单据已选择，不能重复对账！');
                b = true;
                break;
            }
        }
        if (b) {
            continue;
        }


        $('#ycdz_addItemDatagrid').datagrid('appendRow', {
            VERIFY_DATE: selRows[j].VERIFY_DATE,
            FK_DATE: selRows[j].FK_DATE,
            DJ_CODE: selRows[j].DJ_CODE,
            H_ID: selRows[j].H_ID,
            PUB_ID: selRows[j].PUB_ID,
            YINCI: selRows[j].YINCI,
            KAIBEN: selRows[j].KAIBEN,
            ZHUANGZHEN: selRows[j].ZHUANGZHEN,
            H_PRICE: selRows[j].H_PRICE,
            YINSHU: selRows[j].YINSHU,
            COST_RATE: selRows[j].COST_RATE
        });
    }

}

/**
 *  印厂对账的删除明细的按钮
 */
function itemRowDelYCDZ(obj,dgUrl,queryParams){
    // 获取选中的行
    var oldRows = $('#ycdz_addItemDatagrid').datagrid('getSelections');
    if(oldRows.length == 0){
        $.messager.alert("操作提示","请选择一条记录,再进行删除！","info");
        return;
    }
    for (var i = 0; i < oldRows.length; i++) {
        var rowIndex = $('#ycdz_addItemDatagrid').datagrid('getRowIndex', oldRows[i]);
        $('#ycdz_addItemDatagrid').datagrid('deleteRow', rowIndex);
    }
}





